package com.n7mobile.nplayerTest;


import java.util.ArrayList;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;

import com.jayway.android.robotium.solo.Solo;



@SuppressWarnings("unchecked")
public class TestAPK extends ActivityInstrumentationTestCase2 {
	private static final String TARGET_PACKAGE_ID = "com.n7mobile.nplayer"; //CHANGE
	private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.n7mobile.nplayer.glscreen.Main"; //CHANGE
	private static Class launcherActivityClass;
	static {
		try {
			launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}

	public TestAPK() throws ClassNotFoundException {
		super(TARGET_PACKAGE_ID, launcherActivityClass);
	}

	private Solo solo;

	@Override
	protected void setUp() throws Exception {
		solo = new Solo(getInstrumentation(), getActivity());
	}
	
//	public void testPlaySongWMA() {
//		solo.clickOnButton("Songs");
//		solo.clickOnButton(1);
//		solo.sleep(2000);
//		solo.clickOnButton(1);
//	}
//	
//	public void testPlaySongMP3() {
//		solo.clickOnButton("Songs");
//		solo.clickOnButton(2);
//		solo.sleep(2000);
//		solo.clickOnButton(1);
//	}
//	
	public void testNextSong() {
		solo.clickOnButton("Songs");
		solo.clickOnButton(1);	//selected item
		solo.sleep(2000);
		ArrayList<EditText> blist = solo.getCurrentEditTexts();
		solo.clickOnButton(3);	//next song
		solo.sleep(2000);
		solo.clickOnButton(1);	//pause
		solo.sleep(2000);
		boolean different = false;
		for(EditText b : blist) {
			if (!solo.getCurrentEditTexts().contains(b)) {
				different = true;
			}
		}
		assertTrue(different);
	}
//	
	
//	public void testVideoPlayback() {
//		String video = "VIDEO0003";
//		solo.clickOnButton("Videos");
//		//solo.clickOnButton("All Videos");
//		assertTrue(solo.searchText(video));
//		solo.clickInList(0);
//		solo.sleep(3000);
//	}
	
//	public void testPlaylistCreate() {	//todo
//		String playlist = "TestPlaylist";
//		String items = "Sum 41";
//		solo.clickOnButton("Playlists");
//		solo.clickOnButton("Add to Playlist");
//		solo.clickOnButton(items);	//todo
//		solo.clickOnButton("Create new playlist");
//		solo.enterText(null, playlist);
//		assertTrue(solo.searchText(playlist));
//		solo.clickOnButton(playlist);		
//		solo.sleep(3000);
//	}


	@Override
	public void tearDown() throws Exception {
		solo.finishOpenedActivities();
	}
}